package com.itheima.d7_tcp4.ZengTest;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @ClassName clientThread
 * @Author 16799
 * @Date 2025/9/26 20:56
 * @Version 1.0
 * @Description TODO
 **/
public class clientThread extends Thread{

    private Socket socket;
    public clientThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream is = socket.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            while (true){
                try {
                    String msg = dis.readUTF();
                    System.out.println(msg);
                }catch (Exception e){
                    System.out.println("该客户端已关闭： " + socket.getRemoteSocketAddress());
                    dis.close();
                    socket.close();
                    break;
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
